package com.sure0000.thread;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

public class ThreadTest {
    public static void main(String[] args) throws Exception{
        FutureTask<String> future = new FutureTask<>(new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(5000L);
                return "future1";
            }
        });

        Thread thread1 = new Thread(future);
        thread1.start();

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(3000L);
                    System.out.println("thread2");
                } catch (Exception e) {
                    //TODO: handle exception
                    System.out.println(e.getMessage());
                }
            }
        });
        thread2.start();

        while(true) {
            System.out.println("XXXXXX");
            if(future.isDone()) {
                System.out.println(future.get());
                break;
            }
            Thread.sleep(1000L);
        }
    }
}